package com.blate.dogxiao.tools;

import android.content.Context;

import androidx.annotation.Px;

/**
 * 屏幕尺寸工具
 *
 * @author Az
 * on 2020/10/20
 */
public class ScreenSizeTools {

    public static @Px
    int getScreenWidth(Context context) {
        return context.getResources().getDisplayMetrics().widthPixels;
    }

    public static @Px
    int getScreenHeight(Context context) {
        return context.getResources().getDisplayMetrics().heightPixels;
    }

    public static int dpToPx(Context context, float dp) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dp * scale + 0.5f);
    }

    public static int spToPx(Context context, float sp) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (sp * scale + 0.5f);
    }


}
